package cn.scau.server.controller;


import cn.scau.server.pojo.Attendance;
import cn.scau.server.service.AttendanceService;
import cn.scau.server.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 代码不跑我先跑
 * @since 2025-03-30
 */
@RestController
@RequestMapping("/attendance")
@Api(tags = "考勤管理")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;

    @PostMapping("/check")
    @ApiOperation(value = "打卡", notes = "签到/签退打卡")
    public ResultVO checkInOrOut() {
        return attendanceService.checkInOrOut();
    }

    @GetMapping("/myRecords")
    @ApiOperation(value = "查询个人考勤记录", notes = "根据时间范围查询个人考勤记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始日期(yyyy-MM-dd)", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束日期(yyyy-MM-dd)", required = false, dataType = "String")
    })
    public ResultVO getPersonalAttendance(
            @RequestParam String startDate,
            @RequestParam String endDate) {

        return attendanceService.getPersonalAttendance(startDate, endDate);
    }

    @GetMapping("/othersRecords")
    @ApiOperation(value = "查询部门考勤记录", notes = "查看本部门或下级部门员工的考勤记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始日期(yyyy-MM-dd)", required = false, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束日期(yyyy-MM-dd)", required = false, dataType = "String"),
            @ApiImplicitParam(name = "deptId", value = "部门ID", required = true, dataType = "int"),
            @ApiImplicitParam(name = "underEmpId", value = "指定员工ID(可选)", required = false, dataType = "String")
    })
    public ResultVO getDeptAttendance(
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam Integer deptId,
            @RequestParam(required = false) String underEmpId) {
        return attendanceService.getDeptAttendance(startDate, endDate, deptId, underEmpId);
    }
}
